﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Media.Imaging;

namespace iTraffic.UserControls
{
    public partial class PicturesViewer : ChildWindow
    {
        public PicturesViewer()
        {
            InitializeComponent();            
            List<Picture> pictureList = new List<Picture>();
            pictureList.Add(AddPicture("/iTraffic;component/Pictures/1.jpg"));
            pictureList.Add(AddPicture("/iTraffic;component/Pictures/2.jpg"));
            pictureList.Add(AddPicture("/iTraffic;component/Pictures/3.jpg"));
            pictureList.Add(AddPicture("/iTraffic;component/Pictures/4.jpg"));
            lbImage.ItemsSource = pictureList;
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
        }        

        private void lbImage_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (lbImage.SelectedItem != null)
            {
                Preview.Source = ((Picture)lbImage.SelectedItem).Href;
            }
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        private Picture AddPicture(string path)
        {
            return new Picture
            {
                Href = new BitmapImage(
                new Uri(
                    path,
                    UriKind.Relative))
            };
        }
    }

    public class Picture
    {
        public ImageSource Href { get; set; }        
    }
}

